package demo1;

import java.util.HashMap;
import java.util.Map;

class Solution {
    public int[] nextGreaterElement(int[] nums1, int[] nums2) {
           Map<Integer,Integer> map = new HashMap<>() ;
           int[] array = new int[nums1.length];
           for(int i = 0 ; i < nums2.length ; i ++){
              map.put(nums2[i] , i) ;
           }
           for(int i = 0 ; i < array.length ; i ++){
               int tmp = nums1[i] ; 
               int index = map.get(tmp) ;
               array[i] = -1 ;
               while(index < nums2.length){
                   if(tmp < nums2[index]){
                    array[i] = nums2[index];
                    break ;
                   }
                   index ++ ;
               }
           }
           return array;

    }
}